package com.itheima.ticket3;


public class Ticket implements Runnable {
    private static int count = 100;

    @Override
    public void run() {
        //卖票
        while (true) {
            if (maipiao()) break;

        }
    }
    public static synchronized boolean maipiao() {//this
        if (count <=0) {
            return true;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String name = Thread.currentThread().getName();
        count--;
        System.out.println(name + "卖了一张票,剩余" + count + "张票");
        return false;
    }


}
